import React, { useState, useEffect } from 'react';
import { Button, Popover, ButtonProps } from 'antd';

/**
 * 给按钮添加权限
 * @param props
 * @returns
 */
interface Props extends ButtonProps {
  role: string;
}

const AuthButton = (props: Props) => {
  const { children, role, disabled } = props;
  const privilegeList =
    JSON.parse(sessionStorage.getItem('privilegeList')) || [];
  const noAuth = !privilegeList.some(item => item.code == role);
  const disable = noAuth || disabled;
  return noAuth ? (
    ''
  ) : (
    // <Popover title="暂无操作权限" content="请联系管理员" trigger="hover">
    //   <Button {...props} disabled={disable}>
    //     {children}
    //   </Button>
    // </Popover>
    <Button {...props} disabled={disable}>
      {children}
    </Button>
  );
};
export default AuthButton;
